import { createRouter, createWebHashHistory } from "vue-router";
import staticRoutes from "./router-static";
import asyncRoutes from "./router-async";
import { useLog } from "@/store/login";
import { useRouter, useRoute } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...staticRoutes, ...asyncRoutes],
});

router.beforeEach((to, from) => {
  const userlogs = useLog();

  if (!staticRoutes.map((item) => item.name).includes(to.name)) {
    const token = userlogs.token;
    if (!token) {
      // 没有登录，直接跳转到登录页
      console.log(token);
      return "/login";
    }
  }
});

export default router;
